package org.jivesoftware.smack;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.jivesoftware.smack.filter.AndFilter;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.filter.PacketTypeFilter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.IQ.Type;
import org.jivesoftware.smack.packet.Registration;
import org.jivesoftware.smack.util.StringUtils;

public class AccountManager
{
  private Connection connection;
  private Registration info = null;
  private boolean accountCreationSupported = false;

  public AccountManager(Connection paramConnection)
  {
    this.connection = paramConnection;
  }

  void setSupportsAccountCreation(boolean paramBoolean)
  {
    this.accountCreationSupported = paramBoolean;
  }

  public boolean supportsAccountCreation()
  {
    if (this.accountCreationSupported)
      return true;
    try
    {
      if (this.info == null)
      {
        getRegistrationInfo();
        this.accountCreationSupported = (this.info.getType() != IQ.Type.ERROR);
      }
      return this.accountCreationSupported;
    }
    catch (XMPPException localXMPPException)
    {
    }
    return false;
  }

  public Collection<String> getAccountAttributes()
  {
    try
    {
      if (this.info == null)
        getRegistrationInfo();
      Map localMap = this.info.getAttributes();
      if (localMap != null)
        return Collections.unmodifiableSet(localMap.keySet());
    }
    catch (XMPPException localXMPPException)
    {
      localXMPPException.printStackTrace();
    }
    return Collections.emptySet();
  }

  public String getAccountAttribute(String paramString)
  {
    try
    {
      if (this.info == null)
        getRegistrationInfo();
      return (String)this.info.getAttributes().get(paramString);
    }
    catch (XMPPException localXMPPException)
    {
      localXMPPException.printStackTrace();
    }
    return null;
  }

  public String getAccountInstructions()
  {
    try
    {
      if (this.info == null)
        getRegistrationInfo();
      return this.info.getInstructions();
    }
    catch (XMPPException localXMPPException)
    {
    }
    return null;
  }

  public void createAccount(String paramString1, String paramString2)
    throws XMPPException
  {
    if (!supportsAccountCreation())
      throw new XMPPException("Server does not support account creation.");
    HashMap localHashMap = new HashMap();
    Iterator localIterator = getAccountAttributes().iterator();
    while (localIterator.hasNext())
    {
      String str = (String)localIterator.next();
      localHashMap.put(str, "");
    }
    createAccount(paramString1, paramString2, localHashMap);
  }

  public void createAccount(String paramString1, String paramString2, Map<String, String> paramMap)
    throws XMPPException
  {
    if (!supportsAccountCreation())
      throw new XMPPException("Server does not support account creation.");
    Registration localRegistration = new Registration();
    localRegistration.setType(IQ.Type.SET);
    localRegistration.setTo(this.connection.getServiceName());
    paramMap.put("username", paramString1);
    paramMap.put("password", paramString2);
    localRegistration.setAttributes(paramMap);
    AndFilter localAndFilter = new AndFilter(new PacketFilter[] { new PacketIDFilter(localRegistration.getPacketID()), new PacketTypeFilter(IQ.class) });
    PacketCollector localPacketCollector = this.connection.createPacketCollector(localAndFilter);
    this.connection.sendPacket(localRegistration);
    IQ localIQ = (IQ)localPacketCollector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    localPacketCollector.cancel();
    if (localIQ == null)
      throw new XMPPException("No response from server.");
    if (localIQ.getType() == IQ.Type.ERROR)
      throw new XMPPException(localIQ.getError());
  }

  public void changePassword(String paramString)
    throws XMPPException
  {
    Registration localRegistration = new Registration();
    localRegistration.setType(IQ.Type.SET);
    localRegistration.setTo(this.connection.getServiceName());
    HashMap localHashMap = new HashMap();
    localHashMap.put("username", StringUtils.parseName(this.connection.getUser()));
    localHashMap.put("password", paramString);
    localRegistration.setAttributes(localHashMap);
    AndFilter localAndFilter = new AndFilter(new PacketFilter[] { new PacketIDFilter(localRegistration.getPacketID()), new PacketTypeFilter(IQ.class) });
    PacketCollector localPacketCollector = this.connection.createPacketCollector(localAndFilter);
    this.connection.sendPacket(localRegistration);
    IQ localIQ = (IQ)localPacketCollector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    localPacketCollector.cancel();
    if (localIQ == null)
      throw new XMPPException("No response from server.");
    if (localIQ.getType() == IQ.Type.ERROR)
      throw new XMPPException(localIQ.getError());
  }

  public void deleteAccount()
    throws XMPPException
  {
    if (!this.connection.isAuthenticated())
      throw new IllegalStateException("Must be logged in to delete a account.");
    Registration localRegistration = new Registration();
    localRegistration.setType(IQ.Type.SET);
    localRegistration.setTo(this.connection.getServiceName());
    HashMap localHashMap = new HashMap();
    localHashMap.put("remove", "");
    localRegistration.setAttributes(localHashMap);
    AndFilter localAndFilter = new AndFilter(new PacketFilter[] { new PacketIDFilter(localRegistration.getPacketID()), new PacketTypeFilter(IQ.class) });
    PacketCollector localPacketCollector = this.connection.createPacketCollector(localAndFilter);
    this.connection.sendPacket(localRegistration);
    IQ localIQ = (IQ)localPacketCollector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    localPacketCollector.cancel();
    if (localIQ == null)
      throw new XMPPException("No response from server.");
    if (localIQ.getType() == IQ.Type.ERROR)
      throw new XMPPException(localIQ.getError());
  }

  private synchronized void getRegistrationInfo()
    throws XMPPException
  {
    Registration localRegistration = new Registration();
    localRegistration.setTo(this.connection.getServiceName());
    AndFilter localAndFilter = new AndFilter(new PacketFilter[] { new PacketIDFilter(localRegistration.getPacketID()), new PacketTypeFilter(IQ.class) });
    PacketCollector localPacketCollector = this.connection.createPacketCollector(localAndFilter);
    this.connection.sendPacket(localRegistration);
    IQ localIQ = (IQ)localPacketCollector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    localPacketCollector.cancel();
    if (localIQ == null)
      throw new XMPPException("No response from server.");
    if (localIQ.getType() == IQ.Type.ERROR)
      throw new XMPPException(localIQ.getError());
    this.info = ((Registration)localIQ);
  }
}

/* Location:           D:\hygieia\userclient\common\libs\easemobchat_2.1.8.jar
 * Qualified Name:     org.jivesoftware.smack.AccountManager
 * JD-Core Version:    0.6.1
 */